Object.defineProperty(exports, "__esModule", {
    value: !0
});

var e = function(e) {
    if (e && e.__esModule) return e;
    var a = {};
    if (null != e) for (var t in e) Object.prototype.hasOwnProperty.call(e, t) && (a[t] = e[t]);
    return a.default = e, a;
}(require("../../utils/request")), a = getApp();

exports.default = {
    initImageData: function() {
        this.setData({
            CHOOSE_IMAGE_MAX_COUNT: 9,
            remarkImages: [],
            remarkImagesTempPath: []
        });
    },
    removedExistsImagesIds: [],
    chooseUploadImage: function(e, a) {
        var t = this, r = 9 - this.data.remarkImagesTempPath.length - this.data.remarkImages.length;
        wx.chooseImage({
            count: r,
            sizeType: [ "compressed" ],
            success: function(e) {
                t.setData({
                    remarkImagesTempPath: t.data.remarkImagesTempPath.concat(e.tempFilePaths)
                }), a && a();
            }
        });
    },
    removeExistsImage: function(e) {
        var a = e.currentTarget.dataset.index, t = this.data.remarkImages.splice(a, 1);
        this.removedExistsImagesIds.push(t[0].id), this.setData({
            remarkImages: this.data.remarkImages
        });
    },
    removeTempImage: function(e) {
        var a = e.currentTarget.dataset.index;
        this.data.remarkImagesTempPath.splice(a, 1), this.setData({
            remarkImagesTempPath: this.data.remarkImagesTempPath
        });
    },
    previewRemarkImage: function(e) {
        var a = e.currentTarget.id, t = this.data.remarkImages.map(function(e) {
            return e.src;
        }).concat(this.data.remarkImagesTempPath);
        wx.previewImage({
            current: a,
            urls: t
        });
    },
    uploadRemarkImages: function(t, r) {
        r.noLoading || wx.showLoading({
            title: "上传图片中...",
            mask: !0
        });
        var s = t.length, m = 0;
        return new Promise(function(n) {
            var i = [];
            a.getTokens(function(a) {
                !function o(c) {
                    e.upload({
                        url: r.url + "?accesstoken=" + a.accesstoken,
                        name: r.name || "file",
                        filePath: c,
                        formData: r.data
                    }).then(function(e) {
                        return i.push(e), Promise.reject();
                    }).catch(function() {
                        ++m === s ? n(i) : o(t[m]);
                    });
                }(t[m]);
            });
        });
    }
};